package com.android.game.lib.graphics;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

public class GL2SurfaceView extends GLSurfaceView {
	//Variables
		private Context m_Context = null;
		private static String TAG = "GL2JNI_VIEW";
		
		public GL2SurfaceView(Context context) {
			// TODO Auto-generated constructor stub
			super(context);
			m_Context = context;
			Init(false, 0, 0);
			Log.i(TAG, "Constructor 1");
		}
		
		public GL2SurfaceView(Context context, boolean translucent, int depth, int stencil) {
	        super(context);
	        m_Context = context;
	        Init(translucent, depth, stencil);
	        Log.i(TAG, "Constructor 2");
		}
		
		public GL2SurfaceView(Context context, AttributeSet attrs){
			super(context, attrs);
			m_Context = context;
			Init(false, 0, 0);
			Log.i(TAG, "Constructor 3");
		}
		
		private int Init(boolean translucent, int depth, int stencil){
			
			if(translucent){
				this.getHolder().setFormat(PixelFormat.TRANSLUCENT);
			}
			
			setEGLContextClientVersion(2);
			setEGLContextFactory(new GL2ContextFactory()); //Update after
			setEGLConfigChooser(translucent ?
					new GL2ConfigChooser(8, 8, 8, 8, depth, stencil) :
					new GL2ConfigChooser(5, 6, 5, 0, depth, stencil)); //Update after
			setRenderer(new GL2Renderer(m_Context)); //Update after
			
			return 0;
		}
		
		@SuppressLint("ClickableViewAccessibility")
		@Override
		public boolean onTouchEvent(MotionEvent event) {
			// TODO Auto-generated method stub
			switch(event.getAction())
			{
			case MotionEvent.ACTION_DOWN:
				//Log.i("XXX", GL2JniLib.Touch(0,0,false));
				GL2JniLib.Selected();
				break;
			}
			return super.onTouchEvent(event);
		}
}
